package com.waymap.Thread;

import com.waymap.common.Constant;
import com.waymap.utils.mq.MsgProducer;
import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.stereotype.Component;
import javax.jms.Destination;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


@Component
@Slf4j
public class WmsThreads {
    final static ThreadPoolExecutor callThread = new ThreadPoolExecutor(5, 10000,
            2L, TimeUnit.MINUTES,
            new LinkedBlockingQueue<Runnable>(1000), new TheadsFactory("wms-mq"));

    public static void execute(MsgProducer producer, String fromTransType, String transactionId, String transType, String accountId) {
        callThread.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    Destination destination = new ActiveMQQueue("test");
                    producer.sendMessage(destination,"test");
                    //Destination destination = new ActiveMQQueue(Constant.Queue_Name);
                    log.info("***********MQ数据推送*************" + transType + ":" + transactionId + ":" + fromTransType + ":" + accountId);
                    //producer.sendMessage(destination, transType + ":" + transactionId + ":" + fromTransType + ":" + accountId);
                    log.info("*************发送MQ完成********************");
                } catch (Exception e) {
                    log.info(transactionId+"有异常：{}",e.getMessage());
                    /*执行定时逻辑*/
                    /*重启mq*/
                }
            }
        });
    }


}
